home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11022 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: hopper.acm.org!news
  2. From: varnk@e62.diebold.com (Ken Varn)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Beginer C please help me
  5. Date: 21 Mar 1996 15:19:32 GMT
  6. Organization: Diebold
  7. Message-ID: <4irs25$c6m@hopper.acm.org>
  8. References: <DoLCFx.B7x.0.bloor@torfree.net>
  9. NNTP-Posting-Host: 199.218.232.47
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <DoLCFx.B7x.0.bloor@torfree.net>, bz786@torfree.net says...
  15. />
  16. />This may be a stupid mistake but "please help" me.
  17. />Thank you very much.
  18. />
  19. />#include <stdio.h>
  20. />#include <math.h>
  21. />main ()
  22. />{
  23. />float n;
  24. />n=(9/5);
  25. />printf ("n=   %1.3f\n", n);
  26. />}
  27. />I have complied and run the programme & I got the answer n=1.000
  28. />but Iam supposed to get answer 1.8.
  29. />Why I got this answer?
  30.  
  31. Your modifiers on the %f are incorrect.  The usage is 
  32. minimum_width.precision.  In other words, you are telling printf to print the 
  33. number with a minimum of 1 wide with a precision of 3.  Since printf does 
  34. rounding, your result is 1.000.  To correct this, use %3.1f.  This tells 
  35. printf to print a minimum of 3 characters with a precision of 1.
  36.  
  37.